Coverage Report

Created: 2026-04-21 11:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
D:\a\scloud-dns\scloud-dns\src\main.rs
Line
Count
Source
1
use crate::config::Config;
2
use crate::exceptions::SCloudException;
3
use crate::workers::manager::StartGate;
4
use crate::workers::{SCloudWorker, WorkerType};
5
use std::path::Path;
6
use std::sync::Arc;
7
use tokio::sync::mpsc;
8
9
mod config;
10
mod dns;
11
mod exceptions;
12
mod ui;
13
mod utils;
14
mod workers;
15
16
#[tokio::main(flavor = "multi_thread", worker_threads = 8)]
17
0
async fn main() -> Result<(), SCloudException> {
18
0
    let config = Config::from_file(Path::new("./config/config.json"))?;
19
0
    utils::logging::init(config.logging.clone())?;
20
21
0
    if config.logging.dyn_ui == false {
22
0
        println!(
23
0
            r#"
24
0
        ██████╗ ███████╗ ██████╗██╗      ██████╗ ██╗   ██╗██████╗
25
0
        ╚════██╗██╔════╝██╔════╝██║     ██╔═══██╗██║   ██║██╔══██╗  scloud-dns (v0.2.3)
26
0
         █████╔╝███████╗██║     ██║     ██║   ██║██║   ██║██║  ██║      org: https://github.com/2SCloud/
27
0
        ██╔═══╝ ╚════██║██║     ██║     ██║   ██║██║   ██║██║  ██║      rep: https://github.com/2SCloud/scloud-dns
28
0
        ███████╗███████║╚██████╗███████╗╚██████╔╝╚██████╔╝██████╔╝      own: @onihilist
29
0
        ╚══════╝╚══════╝ ╚═════╝╚══════╝ ╚═════╝  ╚═════╝ ╚═════╝
30
0
        "#
31
0
        );
32
0
    } else {
33
0
        ratatui::run(|terminal| ui::App::default().run(terminal));
34
    }
35
36
    //#[cfg(target_os = "windows")]
37
    //{
38
    //    use tokio::net::UdpSocket;
39
    //    use std::sync::Arc;
40
    //    use workers::types::listener::SHARED_UDP_SOCKET;
41
    //    let udp = UdpSocket::bind("0.0.0.0:5353")
42
    //        .await
43
    //        .map_err(|_| SCloudException::SCLOUD_WORKER_LISTENER_BIND_FAILED)?;
44
    //    SHARED_UDP_SOCKET.set(Arc::new(udp)).ok();
45
    //}
46
47
0
    let gate = Arc::new(StartGate::new(1));
48
49
0
    let worker_specs: [(WorkerType, u16); 11] = [
50
0
        (WorkerType::TCP_ACCEPTOR, config.workers.tcp_acceptor),
51
0
        (WorkerType::DOH_ACCEPTOR, config.workers.doh_acceptor),
52
0
        (
53
0
            WorkerType::QUERY_DISPATCHER,
54
0
            config.workers.query_dispatcher,
55
0
        ),
56
0
        (WorkerType::CACHE_LOOKUP, config.workers.cache_lookup),
57
0
        (WorkerType::ZONE_MANAGER, config.workers.zone_manager),
58
0
        (WorkerType::RESOLVER, config.workers.resolver),
59
0
        (WorkerType::CACHE_WRITER, config.workers.cache_writer),
60
0
        (WorkerType::ENCODER, config.workers.encoder),
61
0
        (WorkerType::SENDER, config.workers.sender),
62
0
        (WorkerType::CACHE_JANITOR, config.workers.cache_janitor),
63
0
        (WorkerType::METRICS, config.workers.metrics),
64
0
    ];
65
66
0
    let total = worker_specs.iter().map(|(_, n)| *n as usize).sum();
67
0
    let mut workers: Vec<Arc<SCloudWorker>> = Vec::with_capacity(total);
68
69
0
    for (worker_type, count) in worker_specs {
70
0
        for _ in 0..count {
71
0
            workers.push(Arc::new(SCloudWorker::new(worker_type)?));
72
        }
73
    }
74
75
0
    workers::manager::channels_generation::generate_channels(workers.clone()).await;
76
0
    workers.sort_by_key(|w| w.get_worker_id());
77
78
0
    let mut handles: Vec<tokio::task::JoinHandle<()>> = Vec::new();
79
0
    for w in workers {
80
0
        handles.push(workers::spawn_worker(w, gate.clone()));
81
0
    }
82
83
0
    futures_util::future::pending::<()>().await;
84
0
    Ok(())
85
0
}